package com.ruoyi.modules.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.modules.domain.vo.PayPayInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.modules.domain.PayPayInfo;
import com.ruoyi.modules.service.IPayPayInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付信息Controller
 *
 * @author ruoyi
 * @date 2022-01-22
 */
@Api(tags = "后台接口 - 支付信息")
@RestController
@RequestMapping("/backstage/payPayInfo")
public class PayPayInfoController extends BaseController {
    @Autowired
    private IPayPayInfoService payPayInfoService;

    /**
     * 查询支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('modules:info:list')")
    @ApiOperation(value="支付信息列表", notes="支付信息列表")
    @GetMapping("/list")
    public TableDataInfo list(PayPayInfo payPayInfo, Long agentUserId) {
        startPage();
        List<PayPayInfo> list = payPayInfoService.list(new LambdaQueryWrapper<PayPayInfo>()
            .eq(agentUserId != null, PayPayInfo::getUserId, agentUserId)
            .eq(payPayInfo.getPaymentStatus() != null, PayPayInfo::getPaymentStatus, payPayInfo.getPaymentStatus())
            .orderByDesc(PayPayInfo::getCreateTime)
        );
        return getDataTable(list);
    }

    /**
     * 查询支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('modules:info:list')")
    @ApiOperation(value="支付信息列表", notes="支付信息列表")
    @GetMapping("/listPayPayInfo")
    public TableDataInfo listPayPayInfo(PayPayInfo payPayInfo) {
        startPage();
        List<PayPayInfoVO> list = payPayInfoService.listPayPayInfo();
        return getDataTable(list);
    }

    /**
     * 导出支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('modules:info:export')")
    @Log(title = "支付信息", businessType = BusinessType.EXPORT)
    @ApiOperation(value="导出表格", notes="导出表格")
    @GetMapping("/export")
    public AjaxResult export(PayPayInfo payPayInfo) {
        List<PayPayInfo> list = payPayInfoService.list(new QueryWrapper<>(payPayInfo));
        ExcelUtil<PayPayInfo> util = new ExcelUtil<PayPayInfo>(PayPayInfo.class);
        return util.exportExcel(list, "支付信息数据");
    }

    /**
     * 获取支付信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('modules:info:query')")
    @ApiOperation(value="支付信息详情", notes="支付信息列情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(payPayInfoService.getById(id));
    }

    /**
     * 新增支付信息
     */
    @PreAuthorize("@ss.hasPermi('modules:info:add')")
    @Log(title = "支付信息", businessType = BusinessType.INSERT)
    @ApiOperation(value="支付信息新增", notes="支付信息新增")
    @PostMapping
    public AjaxResult add(@RequestBody PayPayInfo payPayInfo) {
        return toAjax(payPayInfoService.save(payPayInfo));
    }

    /**
     * 修改支付信息
     */
    @PreAuthorize("@ss.hasPermi('modules:info:edit')")
    @Log(title = "支付信息", businessType = BusinessType.UPDATE)
    @ApiOperation(value="支付信息修改", notes="支付信息修改")
    @PutMapping
    public AjaxResult edit(@RequestBody PayPayInfo payPayInfo) {
        return toAjax(payPayInfoService.updateById(payPayInfo));
    }

    /**
     * 删除支付信息
     */
    @PreAuthorize("@ss.hasPermi('modules:info:remove')")
    @Log(title = "支付信息", businessType = BusinessType.DELETE)
    @ApiOperation(value="支付信息删除", notes="支付信息删除")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(payPayInfoService.removeByIds(Arrays.asList(ids)));
    }

}
